package com.cadre.common.utils.common;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;

/* loaded from: DateUtils.class */
public class DateUtils {
    public static final String DATE_PATTERN = "yyyy-MM-dd";
    public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static String format(Date date) {
        return format(date, "yyyy-MM-dd");
    }

    public static String format(Date date, String pattern) {
        if (date != null) {
            return new SimpleDateFormat(pattern).format(date);
        }
        return null;
    }

    public static Date stringToDate(String strDate, String pattern) {
        if (StringUtils.isBlank(strDate)) {
            return null;
        }
        return DateTimeFormat.forPattern(pattern).parseLocalDateTime(strDate).toDate();
    }

    public static Date[] getWeekStartAndEnd(int week) {
        LocalDate date = new LocalDate(new DateTime().plusWeeks(week)).dayOfWeek().withMinimumValue();
        return new Date[]{date.toDate(), date.plusDays(6).toDate()};
    }

    public static Date addDateSeconds(Date date, int seconds) {
        return new DateTime(date).plusSeconds(seconds).toDate();
    }

    public static Date addDateMinutes(Date date, int minutes) {
        return new DateTime(date).plusMinutes(minutes).toDate();
    }

    public static Date addDateHours(Date date, int hours) {
        return new DateTime(date).plusHours(hours).toDate();
    }

    public static Date addDateDays(Date date, int days) {
        return new DateTime(date).plusDays(days).toDate();
    }

    public static Date addDateWeeks(Date date, int weeks) {
        return new DateTime(date).plusWeeks(weeks).toDate();
    }

    public static Date addDateMonths(Date date, int months) {
        return new DateTime(date).plusMonths(months).toDate();
    }

    public static Date addDateYears(Date date, int years) {
        return new DateTime(date).plusYears(years).toDate();
    }
}
